<template>
  <div class="region">
    <div class="content">
      <div class="left v-link address">地区：</div>
      <ul class="v-link">
        <li :class="{active:regionFlag===''}" @click="changeRegion('')">全部</li>
        <li v-for="item in regionArr" :key="item.value" @click="changeRegion(item.value)" :class="{active:regionFlag===item.value}">{{item.name}}</li>
      </ul>
    </div>
  </div>
</template>
      
<script lang="ts" setup>
// @ts-ignore
import {onMounted,ref} from "vue"
// @ts-ignore
import { reqHospitalLevelAndRegion } from "@/api/home"
// @ts-ignore
import { HospitalLevelAndRegionResponseData,HospitalLevelAndRegionArr} from "@/api/home/type"
let $emits=defineEmits(['getRegion'])
// 高亮效果
const regionFlag=ref<string>('')
const changeRegion=(region:string)=>{
  regionFlag.value=region
  $emits('getRegion',region)
}
// 存储地区数据
const regionArr=ref<HospitalLevelAndRegionArr>([])
// 获取地区的数据
const getRegion=async()=>{
  let result:HospitalLevelAndRegionResponseData=await reqHospitalLevelAndRegion('Beijin')
  if(result.code==200){
    regionArr.value=result.data
  }
}
onMounted(()=>{
  getRegion()
})
</script>
      
<style lang="scss" scoped>
.v-link {
  color: #666;
  transition: all 0.2s ease;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
}

.region {
  h1 {
    margin-bottom: 30px;
    font-weight: 700;
    font-size: 16px;
    color: #333;
    letter-spacing: 1px;
  }
  .content {
    display: flex;
    margin-bottom: 10px;
    .left {
      color: #999;
      font-size: 14px;
      margin-bottom: 10px;
      &.hospital {
        width: 60px;
      }
      &.address {
        width: 80px;
      }
    }
    ul {
      display: flex;
      flex-wrap: wrap;
      li {
        color: #666;
        margin-right: 26px;
        font-size: 14px;
        margin-bottom: 10px;

        &.active {
          color: #4490f1;
          font-weight: 700;
        }
      }
      li:hover {
        color: #4490f1;
        font-weight: 700;
      }
    }
  }
}
</style>